package demo.webauthn.config;

import com.yubico.webauthn.RelyingParty;
import com.yubico.webauthn.data.RelyingPartyIdentity;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashSet;

/**
 * @author 1
 * @date 2023-02-01 11:32
 **/
@Configuration
public class RelyingPartyConfig {

    //@Value("${webauthn.host}")
    private String host = "http://localhost:8080";  // 前端项目地址

   // @Value("${webauthn.id}")
    private String webauthnId = "localhost";

    @Bean
    public RelyingParty relyingParty(RegistrationService regisrationRepository) {
        RelyingPartyIdentity rpIdentity = RelyingPartyIdentity.builder()
                .id(webauthnId)
                .name("webauthnTest")
                .build();
        HashSet<String> set = new HashSet<>();
        set.add(host);
        return RelyingParty.builder()
                .identity(rpIdentity)
                .credentialRepository(regisrationRepository)
                .origins(set)
                .build();

    }
}
